package com.iwomy.envpro.platform.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iwomy.envpro.common.core.util.R;
import com.iwomy.envpro.common.excel.annotation.ResponseExcel;
import com.iwomy.envpro.common.log.annotation.SysLog;
import com.iwomy.envpro.platform.dto.AirAbnormalEventDTO;
import com.iwomy.envpro.platform.entity.AirAbnormalEventEntity;
import com.iwomy.envpro.platform.service.AirAbnormalEventService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 异常事件表
 *
 * @author pig
 * @date 2023-08-29 17:58:11
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/airAbnormalEvent" )
@Tag(description = "airAbnormalEvent" , name = "异常事件表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class AirAbnormalEventController {

    private final  AirAbnormalEventService airAbnormalEventService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param airAbnormalEvent 异常事件表
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('platform_airAbnormalEvent_view')" )
    public R getAirAbnormalEventPage(@ParameterObject Page page,@ParameterObject AirAbnormalEventEntity airAbnormalEvent) {
        LambdaQueryWrapper<AirAbnormalEventEntity> wrapper = Wrappers.lambdaQuery(airAbnormalEvent);
        return R.ok(airAbnormalEventService.page(page, wrapper));
    }


    /**
     * 通过id查询异常事件表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('platform_airAbnormalEvent_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(airAbnormalEventService.getById(id));
    }

    /**
     * 新增异常事件表
     * @param airAbnormalEvent 异常事件表
     * @return R
     */
    @Operation(summary = "新增异常事件表" , description = "新增异常事件表" )
    @SysLog("新增异常事件表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('platform_airAbnormalEvent_add')" )
    public R save(@RequestBody AirAbnormalEventEntity airAbnormalEvent) {
        return R.ok(airAbnormalEventService.save(airAbnormalEvent));
    }

    /**
     * 修改异常事件表
     * @param airAbnormalEvent 异常事件表
     * @return R
     */
    @Operation(summary = "修改异常事件表" , description = "修改异常事件表" )
    @SysLog("修改异常事件表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('platform_airAbnormalEvent_edit')" )
    public R updateById(@RequestBody AirAbnormalEventEntity airAbnormalEvent) {
        return R.ok(airAbnormalEventService.updateById(airAbnormalEvent));
    }

    /**
     * 通过id删除异常事件表
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除异常事件表" , description = "通过id删除异常事件表" )
    @SysLog("通过id删除异常事件表" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('platform_airAbnormalEvent_del')" )
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(airAbnormalEventService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param airAbnormalEvent 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('platform_airAbnormalEvent_export')" )
    public List<AirAbnormalEventEntity> export(AirAbnormalEventEntity airAbnormalEvent) {
        return airAbnormalEventService.list(Wrappers.query(airAbnormalEvent));
    }


	/**
	 * 获取指定所有异常事件
	 * @param page
	 * @param airAbnormalEventDTO
	 * @return
	 */
	@GetMapping("/getAirMonitorEquipmentList")
	@PreAuthorize("@pms.hasPermission('platform_airSite_view')" )
	public R getAirAbnormalEventList(Page page,@ParameterObject AirAbnormalEventDTO airAbnormalEventDTO){
		return  R.ok(airAbnormalEventService.getAirAbnormalEventList(page,airAbnormalEventDTO));
	}

/*************************APP接口************************************************/

	/**
	 * 获取指定所有异常事件
	 * @param page
	 * @param airAbnormalEventDTO
	 * @return
	 */
	@GetMapping("/appAirMonitorEquipmentList")
	public R appAirMonitorEquipmentList(Page page,@ParameterObject AirAbnormalEventDTO airAbnormalEventDTO){
		return  R.ok(airAbnormalEventService.getAirAbnormalEventList(page,airAbnormalEventDTO));
	}

}